#pragma once
#include "QAbstractGraphicsShapeItem"

class AbstractShapeItem;
class LineItem;

class NodePort : public QAbstractGraphicsShapeItem
{
public:
	NodePort(AbstractShapeItem*);
	~NodePort(void);

	const static int INPORT=0;   //means in port;
	const static int OUTPORT=1;  //means out port;
	const static int NDPORT=2;   //means no direction

	const static int WOP_PORT=0;
	const static int VM_PORT=1;
	const static int WOP_COLL_PORT=2;
	const static int VM_COLL_PORT=3;
	const static int UNFOLD_PORT=4;

	const static int SIZE=10;	//port固定為10的大小
	const static int RADIUS=6;
	const static int GATE_RADIUS = 6;

	virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) = 0;
	virtual QRectF boundingRect() const = 0;
	virtual int getClass() = 0;
	const std::string & getName() const;
	void setName( const std::string & name );
	virtual int getCategory() = 0;
	std::vector<LineItem*>& getPortLineList();
	int getPortIOType();
	void setPortIOType(int);
	AbstractShapeItem* getParent();
	void setY(int);
	void setX(int);
	int x();
	int y();
	void updateLinePosition();
	void removeAllLinks();
	void removeLineFromVector(LineItem*);	//移除連到此port的指定line
	bool isConnected();

protected:
	AbstractShapeItem* _parent;
	int _portType;				//porttype	 影響形狀
	int _portIOType;			//portiotype 影響外型
	int _x;
	int _y;
	std::string _name;
	void setPortInitVisible();	//設定port在一開始的時候是否出現	
	void mousePressEvent(QGraphicsSceneMouseEvent* );
	void mouseMoveEvent(QGraphicsSceneMouseEvent* );
	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* )=0;
	QGraphicsLineItem* _line;	// 拉線的時候出現的link，並不是最後儲存的link
	std::vector<LineItem*> _portLineList;
	QPainterPath shape () const;
};
